#coding=utf-8
from storm.locals import *
import settings as s
from domains import User,Campaign,Ad,Keyword,ShowRecord,ClickRecord

def is_empty(store):
    if s.db_engine == "mysql":
        r = store.execute("show tables")
        if r.get_all():
            return False
        else:
            return True
            
def create_user(store, name, password):
    
    u = User()
    u.name = name
    u.password = password
    
    store.add(u)
    store.flush()
                
def find_camp(store, user_name, camp_name):
    return store.find(Campaign, Campaign.name==camp_name, \
               Campaign.user_id==User.id, User.name==user_name).one()

def find_ad(store, user_name, ad_name):
    return store.find(Ad, Ad.name==ad_name, \
               Ad.user_id==User.id, User.name==user_name).one()
